#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

class Solution {
    public:
        int sqrt(int x) {
            int lo, hi;
            if (x ==0) return 0;
            if (x < 1) {lo = x; hi = 1;} 
            else {lo = 1; hi = x;}
            int mid;
            while (lo <= hi) {
                cout << lo << " " << hi  << " " << x << endl;
                mid = lo + (hi-lo)/2;
                if (mid == x/mid) return mid;
                else if (mid < x/mid) lo = mid+1;
                else hi = mid-1;
            }
            if (mid < x/mid) return mid;                        
            else return mid-1;
        }
};

//test on 1337 online judge and pass all the test
int main(int argc, char **argv)
{
    Solution mySolution;

    cout << "-----------------Test 1--------------------" << endl;
    //cout << mySolution.sqrt(22*22) << endl;
    //cout << mySolution.sqrt(1) << endl;
    //cout << mySolution.sqrt(100) << endl;
    //cout << mySolution.sqrt(105) << endl;
    cout << mySolution.sqrt(1473634757) << endl;

    cout << "-----------------Test 2--------------------" << endl;


    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
